package com.xujl.mvcbind.db;

import com.xujl.mvcbind.bean.OverTimeEntity;
import com.xujl.mvcbind.db.dao.DaoSession;
import com.xujl.mvcbind.db.dao.OverTimeEntityDao;

import java.util.ArrayList;
import java.util.List;

public class OverTimeHelper {
    private OverTimeEntityDao mDao;

    OverTimeHelper (DaoSession daoSession) {
        mDao = daoSession.getOverTimeEntityDao();
    }

    public void insert (OverTimeEntity entity) {
        mDao.insert(entity);
    }

    public void update (OverTimeEntity entity) {
        mDao.update(entity);
    }

    public List<OverTimeEntity> queryAll (int page, int pageSize) {
        final List<OverTimeEntity> entities = mDao.queryBuilder()
                .offset(page * pageSize)
                .limit(pageSize)
                .orderDesc(OverTimeEntityDao.Properties.Date)
                .list();
        if (entities == null) {
            return new ArrayList<>();
        }
        return entities;
    }

    public List<OverTimeEntity> queryAllForType (int type) {
        final List<OverTimeEntity> entities = mDao.queryBuilder()
                .where(OverTimeEntityDao.Properties.Type.eq(type))
                .list();
        if (entities == null) {
            return new ArrayList<>();
        }
        return entities;
    }

    public void delete (OverTimeEntity entity) {
        mDao.delete(entity);
    }
}
